var e = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), t = require("../../@babel/runtime/helpers/asyncToGenerator"), a = getApp(), r = require("../../http/activityApi.js");

Page({
    data: {
        bgImgUrl: "http://newimg.ap1983.com/prod/20220207/91c31598ab3b4d4d90e9c1201ffed254.jpg",
        indexImgUrl: [ "http://newimg.ap1983.com/prod/20220207/f567224da6ac4690b0dc1bfe5b1e4d41.png", "http://newimg.ap1983.com/prod/20220207/2ac168faa2134fbe94c64521b400c0cf.png", "http://newimg.ap1983.com/prod/20220207/6bbb76d6df8e4b67acf5a86b5f2f9d7c.png" ],
        cateIndex: 0,
        productList: []
    },
    onLoad: function(e) {
        this.setData({
            cateId: e.cateId
        }), this.loadDetails();
    },
    cateItemOnTap: function(e) {
        var t = e.currentTarget.dataset.index;
        this.setData({
            cateIndex: t
        }), this.loadProductList();
    },
    presellItemOnTap: function(e) {
        var t = e.currentTarget.dataset.index, a = this.data.details.peakRecommendList[t];
        this.openProductDetails(a);
    },
    productItemOnTap: function(e) {
        var t = e.currentTarget.dataset.index, a = this.data.productList[t];
        this.openProductDetails(a);
    },
    openProductDetails: function(e) {
        e.brightBoxProductId ? a.gotoPage("/pages/series/series?productId=" + e.brightBoxProductId) : a.gotoPage("/pages/direct-buy-details/direct-buy-details?productId=" + e.blinBoxId);
    },
    loadDetails: function() {
        var n = this;
        return t(e.default.mark(function t() {
            var d, i, c;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.prev = 0, a.showLoading(), e.next = 4, r.rankHome();

                  case 4:
                    if (d = e.sent, n.setData({
                        details: d.data
                    }), !(n.data.cateId >= 0)) {
                        e.next = 16;
                        break;
                    }
                    i = n.data.details.peakTypeList || [], c = 0;

                  case 9:
                    if (!(c < i.length)) {
                        e.next = 16;
                        break;
                    }
                    if (i[c].id != n.data.cateId) {
                        e.next = 13;
                        break;
                    }
                    return n.setData({
                        cateIndex: c
                    }), e.abrupt("break", 16);

                  case 13:
                    c++, e.next = 9;
                    break;

                  case 16:
                    n.loadProductList(), e.next = 23;
                    break;

                  case 19:
                    e.prev = 19, e.t0 = e.catch(0), console.log(e.t0), wx.hideLoading();

                  case 23:
                    return e.prev = 23, e.finish(23);

                  case 25:
                  case "end":
                    return e.stop();
                }
            }, t, null, [ [ 0, 19, 23, 25 ] ]);
        }))();
    },
    loadProductList: function() {
        var n = this;
        return t(e.default.mark(function t() {
            var d, i;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.prev = 0, a.showLoading(), d = n.data.details.peakTypeList[n.data.cateIndex].id, 
                    e.next = 5, r.rankProductList({
                        peakTypeId: d
                    });

                  case 5:
                    i = e.sent, n.setData({
                        productList: i.data
                    }), e.next = 13;
                    break;

                  case 9:
                    e.prev = 9, e.t0 = e.catch(0), console.log(e.t0), n.setData({
                        productList: []
                    });

                  case 13:
                    return e.prev = 13, wx.hideLoading(), e.finish(13);

                  case 16:
                  case "end":
                    return e.stop();
                }
            }, t, null, [ [ 0, 9, 13, 16 ] ]);
        }))();
    }
});